package 集合.练习题;

import java.util.ArrayList;

public class lesson01 {
    public static void main(String[] args) {
        ArrayList<Object> list = new ArrayList<>();
        list.add(new New("新冠疫情病例超千万"));
        list.add(new New("新冠疫情病例超千万,好快呀"));
        for(int i = list.size() - 1; i >=0;i--){
            New o = (New)list.get(i);
            System.out.println(processTitle(o.getTitle()));
        }

    }

    public static String processTitle(String  news){
        if(news == null){
            return "";
        }
        if(news.length() > 6){
            String substring1 = news.substring(0, 6);
            return substring1 + "...";
        }else {
            return news;
        }
    }

}
class New{
    private String title;
    private String desc;

    public New(String title) {
        this.title = title;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public String getDesc() {
        return desc;
    }

    public void setDesc(String desc) {
        this.desc = desc;
    }

    @Override
    public String toString() {
        return "New{" +
                "title='" + title + '\'' +
                '}';
    }
}